<div class="qr" id="topmenu">
    <div class="w1200 qr-menu">
        <div class="logo">
            <a href="/">
                <img src="{{ asset('/static/home/images/logo.png') }}" alt="">
            </a>
        </div>
        <div class="choise">
            <div class="selloc">
                <Icon type="ios-pin-outline"></Icon>
                <span>
                    <script>
                        if(Number(window.localStorage.getItem('city_id')) > 0){
                            document.write(window.localStorage.getItem('city_name'))
                        }else{
                            document.write('{{$city[0]['name']}}')
                        }
                    </script>
                </span>
            </div>
            <div class="list">
                @foreach($city as $c)
                <a href="javascript:;" class="city{{$c->id}}" onclick='changeCity("{{ $c->id }}","{{ $c->name }}","{{$c->longitude}}",{{$c->latitude}})'>{{$c->name}}</a>
                @endforeach
            </div>
        </div>
        <div class="menu" v-cloak>
            <a href="/" class="home">首页</a>
            <a v-if="item.type == 'T'" :href="item.url+'/'+cityId" v-for="(item,index) in topmenu" :class=`menu_${item.id}` :key="index">@{{ item.name }}</a>
            <a v-if="item.type == 'F'" :href="item.url" v-for="(item,index) in topmenu" :key="index" :class=`menu_${item.id}`>@{{ item.name }}</a>
        </div>
{{--        <div class="search">--}}
{{--            <Icon type="ios-search-outline"></Icon>--}}
{{--            <span>请输入楼盘名称</span>--}}
{{--        </div>--}}
        <div class="map">
            <a href="{{ route('home.maproom') }}">
                <i-button type="primary" icon="ios-map-outline">地图找房</i-button>
            </a>
        </div>
        <div class="tel">
            <div class="txt">
                <Icon type="ios-call"></Icon>
                <span>咨询电话</span>
            </div>
            <div class="number">0898-12345678</div>
        </div>
        <input type="hidden" id="cityIndex" value="{{$city[0]["id"]}}">
    </div>
</div>

<script>
    new Vue({
        el: "#topmenu",
        data: {
            topmenu: [],
            cityId: window.localStorage.getItem('city_id')?window.localStorage.getItem('city_id'):document.getElementById("cityIndex").value,
        },
        methods:{
            getMenus(){
                var _this = this
                axios.post("/getMenu").then(function (res) {
                    if(res.data.code === 0) {
                        _this.topmenu = res.data.menu
                    }
                }).catch(function (error) {

                });
            }
        },
        created(){
            var id = window.localStorage.getItem('city_id')
            if(!Number(id)){
                window.localStorage.setItem('city_id','{{$city[0]["id"]}}');
                window.localStorage.setItem('city_name','{{$city[0]["name"]}}');
                window.localStorage.setItem('longitude','{{$city[0]["longitude"]}}');
                window.localStorage.setItem('latitude','{{$city[0]["latitude"]}}');
            }
            $(".city"+id).addClass("active")
            this.$nextTick(function () {
                this.getMenus()
            })
        },
        mounted(){
            // console.log(this.topmenu)
        }
    })
    {{--$(function () {--}}
    {{--    var id = window.localStorage.getItem('city_id')--}}
    {{--    if(!Number(id)){--}}
    {{--        window.localStorage.setItem('city_id','{{$city[0]["id"]}}');--}}
    {{--        window.localStorage.setItem('city_name','{{$city[0]["name"]}}');--}}
    {{--        window.localStorage.setItem('longitude','{{$city[0]["longitude"]}}');--}}
    {{--        window.localStorage.setItem('latitude','{{$city[0]["latitude"]}}');--}}
    {{--    }--}}
    {{--    $(".city"+id).addClass("active")--}}
    {{--})--}}
    function changeCity(id,name,longitude,latitude) {
        window.localStorage.setItem('city_id',id);
        window.localStorage.setItem('city_name',name);
        window.localStorage.setItem('longitude',longitude);
        window.localStorage.setItem('latitude',latitude);
        // location.href = '/newhouse/'+id
        location.href = '/'
    }
</script>
